﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfDjackVehicle : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void getUserInfo(string djackId)
        {
            if (string.IsNullOrEmpty(djackId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo vehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataSet ds = vehicleInfo.SelectByIds(djackId, "");
                if (ds == null)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                string isLogin = msBsc.SvRef.UserInfo.Online ? "true" : "false";
                this.ExecJScript(@"setDjackInfo(" + retJson + ",'" + isLogin + "');");
            }
        }

        private void djackVehicle(string djackId)
        {
            if (string.IsNullOrEmpty(djackId))
            {
                return;
            }
            using (msBsc.AppLogic.DataAlc.CBizDjackSpecieInfo specieInfo = new AppLogic.DataAlc.CBizDjackSpecieInfo())
            {
                DataSet ds = specieInfo.SelectVehicleById(djackId);
                if (ds == null)
                {
                    return;
                }
                DataColumn dr = new DataColumn("VEHICLE_BRAND_NAME");
                ds.Tables[0].Columns.Add(dr);
                DataColumn dr1 = new DataColumn("VEHICLE_SERVICE_TYPE_NAME");
                ds.Tables[0].Columns.Add(dr1);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    ds.Tables[0].Rows[i]["VEHICLE_BRAND_NAME"] = Enum.GetName(typeof(msBsc.AppLogic.DataAlc.cls.CommonEnum.VehicleBrandEnum), Convert.ToInt32(ds.Tables[0].Rows[i]["VEHICLE_BRAND"].ToString()));

                    ds.Tables[0].Rows[i]["VEHICLE_SERVICE_TYPE_NAME"] = Enum.GetName(typeof(msBsc.AppLogic.DataAlc.cls.CommonEnum.ServiceTypeEnum), Convert.ToInt32(ds.Tables[0].Rows[i]["VEHICLE_SERVICE_TYPE"].ToString()));
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp_vehicle').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#vehicle-list-wrap').html(render);
                            });");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                string djackId = this.GetParamHtValue("djackId");
                getUserInfo(djackId);
                djackVehicle(djackId);
                getForumList(djackId);
                base.DoAction();
            }

        }

        private void getForumList(string djackId)
        {
            string pIndex = this.GetParamHtValue("pIndex");
            string pRows = this.GetParamHtValue("pRows");
            using (msBsc.AppLogic.DataAlc.CBizSourcePosts sourcePosts = new AppLogic.DataAlc.CBizSourcePosts())
            {

                Epm.AppLogic.Framework.CDbParmCollection parm = new Epm.AppLogic.Framework.CDbParmCollection();
                parm.Add(new Epm.AppLogic.Framework.CDbParm("djkid", ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.String, 36, djackId));
                DataSet ds = sourcePosts.DataObj.QueryBySQL(@"SELECT
	T.*
	,B.CUSTOMER_NICK
	,B.CUSTOMER_DEFAULT_PIC
	FROM
	(SELECT 
	A.SOURCE_POSTS_ID
	,A.SOURCE_POSTS_TITLE
	,A.POSTS_PUBLISH_TIME
	,A.POSTS_PUBLISH_BY
    ,A.POSTS_IS_BOUTIQUE
	FROM 
	DJK_SOURCE_POSTS A 
	WHERE 
	(@djkid='' OR A.POSTS_PUBLISH_BY=@djkid)
	AND A.POSTS_STATUS=2) T
	LEFT JOIN DJK_CUSTOMER_REGISTER B
	ON T.POSTS_PUBLISH_BY=B.CUSTOMER_REGISTER_ID
    ORDER BY T.POSTS_IS_BOUTIQUE DESC,T.POSTS_PUBLISH_TIME DESC", parm);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"
                            var _html = $('#svc_list_temp').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#forumInfo').html(render);
                            });");
            }
        }
    }
}